package cn.javaweb.group0.servlet;

import cn.javaweb.entity.User;
import cn.javaweb.group0.model.RoleModel;
import cn.javaweb.library.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/rolelist")
public class RoleListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getAttribute("user");
        RoleModel roleModel = new RoleModel();

        List<String> rolelist = roleModel.getRolesByUser(user);

        resp.getWriter().print(
            AjaxResult.success(
                    "OK",
                    rolelist)
        );
    }
}
